//根据浏览器获取ajax请求初始化

function getRequest(){
     var request0 = null;
	if (window.ActiveXObject) { // IE
         for(var i = 5; i > 0; i--){
	        try{
		        if(i == 2){ 
			        request0 = new ActiveXObject("Microsoft.XMLHTTP");
		        }else{
			        request0 = new ActiveXObject("MSXML2.XMLHTTP." + i + ".0");
		        }        
		        break;
	        } catch(e){
		        request0 = null;
	        }
        }
           
   /**
       var msxmls = ['MSXML2', 'MICROSOFT', 'MSXML3'];
       for(var i = 0; i < 3; i++){
          try {
             request0 = new ActiveXObject(msxmls[i] + ".XMLHTTP.5.0");
            // request0.setRequestHeader('Content-Type', 'UTF-8');
            // alert(i);
             //request0.setRequestHeader('Content-Type', 'text/xml');             
          } catch (e) {}
          if(request0 != null){
            //alert(i);
            break;
          }
       }
   */               
    } else if(window.XMLHttpRequest) { //Mozilla
        request0 = new XMLHttpRequest();
        if (request0.overrideMimeType) {//MiME
            request0.overrideMimeType('text/xml');
        }
    }
    if (request0 == null) {
		window.alert("Browser cannot create XMLHttpRequest. ");
		return null;
	}
    
	return request0;
}

//处理ajax
function ajax(url,returnFun)
{
	var req = getRequest();
	
	 if(req == null){
   		alert('Browser cannot create XMLHttpRequest.');
        return;
    }
    
    var returnValue = null;
 	req.onreadystatechange = function(){
  	    if (req.readyState == 4){
          if(req.status == 200) { 
             try{
                 returnValue = req.responseText; 
                // alert(returnValue);             	             
	              returnFun(returnValue);         
	         } catch (e){
	         
	         alert(e.message);
	         alert("请求失败");
	             
	         }
	       } else { 
	        
	       }
	    } else {
	      
	    }
 	}
	try{	
		req.open("GET", url,true);
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
		req.send(null);
    } catch (e){
	   alert(e.message);
    }
}

//获取公告的信息
function loadXML(id,url){
 var req;
 
 function loadXMLDoc(url) {
  req = false;
     if(window.XMLHttpRequest && !(window.ActiveXObject)) {
      try {
    req = new XMLHttpRequest();
         } catch(e) {
    req = false;
         }
      } else if(window.ActiveXObject) {
          try {
           req = new ActiveXObject("Microsoft.XMLHTTP");
         } catch(e) {
          try {
             req = new ActiveXObject("Microsoft.XMLHTTP");
          } catch(e) {
             req = false;
          }
   }
     }
  if(req) {
   req.onreadystatechange = processReqChange;
   req.open("GET", url,true);
   req.send("");
  } 
 }
 function processReqChange() {
 

     if (req.readyState == 4) {
         if (req.status == 200) {
          	var doc =  document.getElementById(id);
            doc.innerHTML = req.responseText;
          } else {
          }
      }
 }
 loadXMLDoc(url);
}
